package com.gooagoo.supercrm.app;

import android.util.Log;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;


import de.mindpipe.android.logging.log4j.LogConfigurator;

public class ConfigureLog4J
{
	private Logger log = Logger.getLogger(ConfigureLog4J.class);
	private static SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");

	public ConfigureLog4J()
	{
		initLog4j();
	}

	public void uploadLog()
	{
	}

	private void initLog4j()
	{
		Log.d("TAG","initLog4j");
		try {
		    LogConfigurator logConfigurator = new LogConfigurator();
		    // 以时间名来作为文件明
		    String filename = format.format(new Date())+".txt";

		    logConfigurator.setFileName("/sdcard" + File.separator + "crmlogs" + File.separator + filename);

		    logConfigurator.setRootLevel(Level.INFO);

		    logConfigurator.setLevel("org.apache", Level.ERROR);
		    //%d %-5p [%c{2}]-[%L] %m%n
		    logConfigurator.setFilePattern("%d %-5p [%c{2}]-[%L] %m%n");
		    
		    //%-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
		    logConfigurator.setMaxFileSize(1024 * 1024 * 10);
		    logConfigurator.setImmediateFlush(true);
		    logConfigurator.configure();
		} catch (Exception e) {
		    e.printStackTrace();
		}
		
	}
}